from common.base import Base, get_driver
from selenium.webdriver.common.by import By

import time

from page.login_page import LoginPage


class OrderlistPage(Base):

    # 点击用户中心
    def user(self):
        # self.click((By.CLASS_NAME,''))
        self.click((By.PARTIAL_LINK_TEXT, '用户中心'))

    # 点击我的订单
    def order_list(self, ):
        # print(1111)
        time.sleep(2)
        self.click((By.PARTIAL_LINK_TEXT,'我的订单'))

    # 查询文本内容
    def get_test(self):
        time.sleep(1)
        text = self.get_text((By.XPATH, '//tr[2]/td[4]'))

        # print(text)
        text = text.split(',')
        text = text[1]
        return text


if __name__ == '__main__':
    driver = get_driver()
    driver.get('http://localhost:8080/ecshop/user.php?act=order_list')

    login = LoginPage(driver)

    username = 'root2'
    password = 'root1234'
    # 登录
    login.input_username(username)
    login.input_password(password)
    login.input_submit()

    order = OrderlistPage(driver)
    order.user()
    time.sleep(2)
    order.order_list()
    print(order.get_test())
    # order.quit()
